# Maintainer: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgname=xdg-utils
# https://gitlab.freedesktop.org/xdg/xdg-utils/commits/master
_commit=21fb316bea83e3374eafc7fbf1e25a0ccdda92cb # master # 2023-11-15
pkgver=1.2.0r17+g21fb316
pkgrel=1
pkgdesc="Command line tools that assist applications with a variety of desktop integration tasks"
arch=('any')
url="https://www.freedesktop.org/wiki/Software/xdg-utils/"
license=('MIT')
depends=('sh' 'file' 'xorg-xset' 'xorg-xprop') # xset + xprop needed inside xdg-screensaver
makedepends=('docbook-xsl' 'lynx' 'xmlto' 'git')
optdepends=('kde-cli-tools: for KDE Plasma5 support in xdg-open'
            'exo: for Xfce support in xdg-open'
            'pcmanfm: for LXDE support in xdg-open'
            'perl-file-mimeinfo: for generic support in xdg-open'
            'perl-net-dbus: Perl extension to dbus used in xdg-screensaver'
            'perl-x11-protocol: Perl X11 protocol used in xdg-screensaver')
source=(#https://portland.freedesktop.org/download/$pkgname-$pkgver.tar.gz
        "git+https://gitlab.freedesktop.org/xdg/xdg-utils.git#commit=$_commit"
)
sha256sums=('SKIP')
#validpgpkeys=('8B75CA7811367175D05F3B03C43570F80CC295E6') # "Per Olofsson <pelle@pqz.se>"

pkgver() {
  cd $pkgname
#  git describe --tags | sed 's/^v//;s/-/+/g'
  # filter tag to avoid need for epoch when the release happens
  git describe --tags | sed 's/^v//;s/-beta1-/r/;s/-/+/g'
}

prepare() {
#  cd $pkgname #-$pkgver

#  NOCONFIGURE=1 ./autogen.sh

  cd $pkgname
}

build() {
  cd $pkgname #-$pkgver
  ./configure --prefix=/usr --mandir=/usr/share/man
  make
}

package() {
  cd $pkgname #-$pkgver
  make DESTDIR="${pkgdir}" install
  install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  # install empty directory to prevent xdg-desktop-menu install *.desktop to fail, see FS#33316
  install -dm755 "$pkgdir"/usr/share/desktop-directories
}
